/*  
 * Actipro Software's WPF DataGrid / Editors Integration Add-on
 * http://actipro.codeplex.com/
 * 
 * Copyright (c) 2009-2015 Actipro Software LLC. 
 *  
 * This source code is subject to the terms of the Microsoft Public License (Ms-PL). 
 *  
 * Redistribution and use in source and binary forms, with or without modification, 
 * is permitted provided that redistributions of the source code retain the above 
 * copyright notices and this file header. 
 *  
 * Additional copyright notices should be appended to the list above. 
 * 
 * For details, see <http://www.opensource.org/licenses/ms-pl.html>. 
 *  
 * All other rights reserved. 
 *
 */  


using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows;
using System.Windows.Media;
using ActiproSoftware.Windows.Controls.Editors.Interop.DataGrid.Primitives;

namespace ActiproSoftware.Windows.Controls.Editors.Interop.DataGrid {

	/// <summary>
	/// Represents a data-bound column for use in a <c>DataGrid</c> that utilizes the <see cref="BrushEditBox"/>.
	/// </summary>
	public class DataGridBrushColumn : DataGridTypeSpecificEditBoxColumnBase<Brush> {

		#region Dependency Properties

		/// <summary>
		/// Identifies the <see cref="AllowGradientBrushes"/> dependency property.  This field is read-only.
		/// </summary>
		/// <value>The identifier for the <see cref="AllowGradientBrushes"/> dependency property.</value>
		public static readonly DependencyProperty AllowGradientBrushesProperty = BrushEditBox.AllowGradientBrushesProperty.AddOwner(typeof(DataGridBrushColumn),
			new FrameworkPropertyMetadata(true, OnNotifyablePropertyValueChanged));

		/// <summary>
		/// Identifies the <see cref="BrushPreviewVisibility"/> dependency property.  This field is read-only.
		/// </summary>
		/// <value>The identifier for the <see cref="BrushPreviewVisibility"/> dependency property.</value>
		public static readonly DependencyProperty BrushPreviewVisibilityProperty = BrushEditBox.BrushPreviewVisibilityProperty.AddOwner(typeof(DataGridBrushColumn),
			new FrameworkPropertyMetadata(Visibility.Visible, OnNotifyablePropertyValueChanged));

		/// <summary>
		/// Identifies the <see cref="IsAlphaComponentEditable"/> dependency property.  This field is read-only.
		/// </summary>
		/// <value>The identifier for the <see cref="IsAlphaComponentEditable"/> dependency property.</value>
		public static readonly DependencyProperty IsAlphaComponentEditableProperty = BrushEditBox.IsAlphaComponentEditableProperty.AddOwner(typeof(DataGridBrushColumn),
			new FrameworkPropertyMetadata(true, OnNotifyablePropertyValueChanged));

		/// <summary>
		/// Identifies the <see cref="IsAlphaComponentVisible"/> dependency property.  This field is read-only.
		/// </summary>
		/// <value>The identifier for the <see cref="IsAlphaComponentVisible"/> dependency property.</value>
		public static readonly DependencyProperty IsAlphaComponentVisibleProperty = BrushEditBox.IsAlphaComponentVisibleProperty.AddOwner(typeof(DataGridBrushColumn),
			new FrameworkPropertyMetadata(true, OnNotifyablePropertyValueChanged));

		#endregion // Dependency Properties
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////
		#region OBJECT
		/////////////////////////////////////////////////////////////////////////////////////////////////////

		/// <summary>
		/// Initializes the <see cref="DataGridBrushColumn"/> class.
		/// </summary>
		[SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline")]
		static DataGridBrushColumn() {
			DropDownButtonVisibilityProperty.OverrideMetadata(typeof(DataGridBrushColumn), new FrameworkPropertyMetadata(Visibility.Visible, DropDownButtonVisibilityProperty.DefaultMetadata.PropertyChangedCallback));
		}

		#endregion // OBJECT

		/////////////////////////////////////////////////////////////////////////////////////////////////////
		#region PUBLIC PROCEDURES
		/////////////////////////////////////////////////////////////////////////////////////////////////////

		/// <summary>
		/// Gets or sets a value indicating whether gradient brushes can be entered by the end user.
		/// This is a dependency property.
		/// </summary>
		/// <value>
		/// <c>true</c> if gradient brushes can be entered by the end user; otherwise <c>false</c>.
		/// The default value is <c>true</c>.
		/// </value>
		public bool AllowGradientBrushes {
			get { return (bool)this.GetValue(DataGridBrushColumn.AllowGradientBrushesProperty); }
			set { this.SetValue(DataGridBrushColumn.AllowGradientBrushesProperty, value); }
		}
	
		/// <summary>
		/// Applies standard values to the specified target element.
		/// </summary>
		/// <param name="targetElement">The target element.</param>
		protected override void ApplyStandardValues(FrameworkElement targetElement) {
			if (targetElement is BrushEditBox) {
				this.ApplyValue(AllowGradientBrushesProperty, targetElement, BrushEditBox.AllowGradientBrushesProperty);
				this.ApplyValue(BrushPreviewVisibilityProperty, targetElement, BrushEditBox.BrushPreviewVisibilityProperty);
				this.ApplyValue(IsAlphaComponentEditableProperty, targetElement, BrushEditBox.IsAlphaComponentEditableProperty);
				this.ApplyValue(IsAlphaComponentVisibleProperty, targetElement, BrushEditBox.IsAlphaComponentVisibleProperty);
			}
			base.ApplyStandardValues(targetElement);
		}

		/// <summary>
		/// Gets or sets the visibility of the associated brush preview.
		/// This is a dependency property.
		/// </summary>
		/// <value>
		/// The visibility of the associated brush preview.
		/// The default value is <c>Visibility.Visible</c>.
		/// </value>
		public Visibility BrushPreviewVisibility {
			get { return (Visibility)this.GetValue(DataGridBrushColumn.BrushPreviewVisibilityProperty); }
			set { this.SetValue(DataGridBrushColumn.BrushPreviewVisibilityProperty, value); }
		}

		/// <summary>
		/// Gets the type of the edit box.
		/// </summary>
		/// <returns>The <see cref="BrushEditBox"/> type.</returns>
		protected override Type GetEditBoxType() {
			return typeof(BrushEditBox);
		}

		/// <summary>
		/// Gets or sets a value indicating whether the alpha component is editable.
		/// This is a dependency property.
		/// </summary>
		/// <value>
		/// <c>true</c> if the alpha component is editable; otherwise <c>false</c>.
		/// The default value is <c>true</c>.
		/// </value>
		public bool IsAlphaComponentEditable {
			get { return (bool)this.GetValue(DataGridBrushColumn.IsAlphaComponentEditableProperty); }
			set { this.SetValue(DataGridBrushColumn.IsAlphaComponentEditableProperty, value); }
		}

		/// <summary>
		/// Gets or sets a value indicating whether the alpha component is visible.
		/// This is a dependency property.
		/// </summary>
		/// <value>
		/// <c>true</c> if the alpha component is visible; otherwise <c>false</c>.
		/// The default value is <c>true</c>.
		/// </value>
		public bool IsAlphaComponentVisible {
			get { return (bool)this.GetValue(DataGridBrushColumn.IsAlphaComponentVisibleProperty); }
			set { this.SetValue(DataGridBrushColumn.IsAlphaComponentVisibleProperty, value); }
		}

		#endregion // PUBLIC PROCEDURES
	}
}
